package cn.qiyu5522.tk_ems.controller.admin;


import cn.qiyu5522.tk_ems.entity.Resume;
import cn.qiyu5522.tk_ems.entity.dto.QueryParamDTO;
import cn.qiyu5522.tk_ems.entity.dto.ResumeDTO;
import cn.qiyu5522.tk_ems.myanotation.WebLog;
import cn.qiyu5522.tk_ems.result.R;
import cn.qiyu5522.tk_ems.service.ResumeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Tonkey
 * @since 2023-02-25
 */
@Api(tags = "简历信息管理")
@RestController
@RequestMapping("admin/resume")
public class ResumeController {
    @Resource
    private ResumeService resumeService;
    

    @WebLog(description = "分页条件查询简历列表")
    @ApiOperation("简历列表查询")
    @ApiImplicitParam(name = "queryParamDTO", value = "条件查询对象", required = true,dataType ="QueryParamDTO" ,dataTypeClass = QueryParamDTO.class)
    @PostMapping("/query")
    public R query(@Validated(QueryParamDTO.Query.class) @RequestBody QueryParamDTO<ResumeDTO> queryParamDTO) {
        return resumeService.queryResumeByPageCondition(queryParamDTO);
    }
    @WebLog(description = "简历新增--批量")
    @ApiOperation("简历新增")
    @ApiImplicitParam(name = "ResumeDTOs", value = "简历新增", required = true,dataType = "List",dataTypeClass = List.class)
    @PostMapping("/add")
    public R add(@Validated(Resume.Insert.class) @RequestBody List<ResumeDTO> ResumeDTOs) {
        return resumeService.saveMore(ResumeDTOs);
    }
    @WebLog(description = "简历编辑")
    @ApiOperation("简历编辑")
    @ApiImplicitParam(name = "resumeDTO", value = "简历实体类对象", required = true, defaultValue = "{}", dataTypeClass = ResumeDTO.class)
    @PutMapping("/edit")
    public R edit(@Validated(Resume.Update.class) @RequestBody ResumeDTO resumeDTO) {
        Resume resume = new Resume();
        BeanUtils.copyProperties(resumeDTO,resume);
        boolean b = resumeService.updateById(resume);
        return b ? R.ok().message("编辑成功") : R.error().message("编辑失败");
    }
    @WebLog(description = "简历删除")
    @ApiOperation("简历删除")
    @ApiImplicitParam(name = "ids", value = "简历编号集合", required = true, defaultValue = "[]", dataTypeClass = List.class)
    @PostMapping("/remove")
    public R remove(@RequestBody List<Long> ids) {
        boolean b = resumeService.removeByIds(ids);
        return b ? R.ok().message("删除成功!"):R.error().message("删除失败");
    }

    @ApiOperation("根据简历编号查询简历信息")
    @ApiImplicitParam(name = "id", value = "简历编号", required = true, dataTypeClass = Integer.class)
    @GetMapping("/queryResumeById/{id}")
    public R queryResumeById(
            @NotNull(message = "简历编号不能为空")
            @PathVariable Integer id) {
        return resumeService.queryResumeById(id);
    }
    @ApiOperation("根据学号编号查询简历信息")
    @ApiImplicitParam(name = "id", value = "简历编号", required = true, dataTypeClass = Long.class)
    @GetMapping("/queryResumeByStudentId/{id}")
    public R queryResumeByStudentId(
            @PathVariable Long id) {
        return resumeService.queryResumeByStudentId(id);
    }
    
}
